//
// Created by lwj12 on 24-8-6.
//

#ifndef TEST_8_16_DATE_H
#define TEST_8_16_DATE_H
#include <iostream>
#include <cmath>
#include <cassert>
using namespace std;

class Date {
    friend ostream& operator<<(ostream& out, const Date& d);
    friend istream& operator<<(istream& in, Date& d);
public:
    void Print();
    static int GetMonthDay(int year, int month)
    {
        assert(month > 0 && month < 13);
        static int day[13] = {-1, 31,28,31,30,31,30,31,31,30,31,30,31};
        if(month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) return 29;
        return day[month];
    }
    //explicit : 减少潜在的隐式转换问题
    explicit Date(int year = 1, int month = 1, int day = 1);
    //析构和拷贝构造其实不需要，有malloc之类的指向类才需要
    ~Date();
    Date(const Date& d);

    Date& operator=(const Date& d);
    int operator-(const Date& d);

    Date operator+(int day);
    Date& operator+=(int day);
    Date operator-(int day);
    Date& operator-=(int day);

    bool operator<(const Date& d);
    bool operator==(const Date& d);
    bool operator<=(const Date& d);
    bool operator>(const Date& d);
    bool operator>=(const Date& d);

    //为了区分++前置和后置, 给后置加了个int类型参数
    Date& operator++();
    Date operator++(int);
private:
    int _year;
    int _month;
    int _day;
};

ostream& operator<<(ostream& out, const Date& d);
istream& operator<<(istream& in, Date& d);
#endif//TEST_8_16_DATE_H
